@echo off
echo 正在修复PowerShell问题...

REM 停止当前占用8080端口的进程
echo 正在停止占用8080端口的进程...
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :8080 ^| findstr LISTENING') do (
    echo 停止进程 PID: %%a
    taskkill /PID %%a /F 2>nul
)

REM 启动WebSocket服务器
echo 正在启动WebSocket服务器...
start "WebSocket Server" cmd /k "python simple_websocket_server.py"

REM 等待服务器启动
timeout /t 3 /nobreak >nul

REM 检查APK文件
echo.
echo 检查APK文件...
if exist "app\build\outputs\apk\release\app-release.apk" (
    echo ✅ Release APK已生成: app\build\outputs\apk\release\app-release.apk
    echo 文件大小:
    dir "app\build\outputs\apk\release\app-release.apk" | findstr "app-release.apk"
) else (
    echo ❌ Release APK未找到
)

if exist "app\build\outputs\apk\debug\app-debug.apk" (
    echo ✅ Debug APK已生成: app\build\outputs\apk\debug\app-debug.apk
    echo 文件大小:
    dir "app\build\outputs\apk\debug\app-debug.apk" | findstr "app-debug.apk"
) else (
    echo ❌ Debug APK未找到
)

echo.
echo PowerShell问题已修复，现在可以使用以下命令：
echo 1. 安装APK: adb install -r app\build\outputs\apk\release\app-release.apk
echo 2. 查看日志: adb logcat -s WebSocketManager:V
echo 3. 启动应用: adb shell am start -n com.example.myapplication/.LoginActivity
echo.
pause 